import 'package:enterprise_v6_app/app/components/special_operation/custom_file_upload_page.dart';
import 'package:enterprise_v6_app/app/components/special_operation/custom_high_input_page.dart';
import 'package:enterprise_v6_app/app/components/special_operation/custom_icon_title_view.dart';
import 'package:enterprise_v6_app/app/components/special_operation/custom_input_page.dart';
import 'package:enterprise_v6_app/app/components/special_operation/custom_multi_signature_page.dart';
import 'package:enterprise_v6_app/app/components/special_operation/custom_select_function.dart';
import 'package:enterprise_v6_app/app/components/special_operation/custom_select_page.dart';
import 'package:enterprise_v6_app/app/components/special_operation/custom_select_relation_page.dart';
import 'package:enterprise_v6_app/app/components/special_operation/custom_select_work_user_page.dart';
import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/modules/application/special_operation/special_list/job_ticket/application/ground_job_application/ground_job_application_controller.dart';

///动土作业-作业申请
class GroundJobApplicationPage extends StatelessWidget {
  GroundJobApplicationPage({required this.isEnabled, required this.isChange, super.key});

  //节点是否可编辑
  final bool isEnabled;

  // 是否在交接班中
  final bool isChange;

  final controller = Get.put(GroundJobApplicationController());

  /// 获取基本作业信息
  Widget _getBasicJobWidget() {
    return Container(
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(8.w),
      ),
      child: Column(
        children: [
          const CustomIconTitleView(
            title: '作业基本信息',
          ),
          Container(
            color: const Color(0xFFF5F7FC),
            height: 1.w,
          ),
          Container(
            padding: EdgeInsets.symmetric(horizontal: 13.w),
            child: Column(
              children: [
                CustomInputPage(
                  title: '作业编号',
                  isEnabled: isEnabled && !isChange,
                  text: controller.executeTicketReceipt.receiptNo,
                  onCallBack: (value) {
                    controller.executeTicketReceipt.receiptNo = value;
                  },
                ),
                CustomSelectPage(
                    title: '计划作业时间',
                    selectText:
                        '${controller.executeTicketReceipt.ticketPlanList!.planStartDate}\n        至\n${controller.executeTicketReceipt.ticketPlanList!.planEndDate}',
                    isEnabled: false,
                    onCallBack: () {}),
                CustomHighInputPage(
                  title: '作业内容',
                  text: controller.executeTicketReceipt.ticketPlanList!.ticketContent,
                  onCallBack: (value) {},
                  isEnabled: false,
                  isShowDivider: false,
                ),
                CustomInputPage(
                  title: '申请单位',
                  text: controller.executeTicketReceipt.ticketPlanList!.applyDepartmentName,
                  onCallBack: (value) {},
                  isEnabled: false,
                ),
                CustomSelectPage(
                    title: '作业申请时间',
                    isEnabled: isEnabled && !isChange,
                    selectText: controller.executeTicketReceipt.applyDate!,
                    onCallBack: () {
                      controller.showDatePicker();
                    }),
                CustomSelectPage(
                  title: '作业地点',
                  selectText: controller.executeTicketReceipt.workOtherDataDTO!.otherTicketAddress!,
                  isEnabled: isEnabled && !isChange,
                  onCallBack: () {
                    controller.locationSelect();
                  },
                ),
                CustomInputPage(
                  title: '作业深度',
                  text: controller.executeTicketReceipt.workOtherDataDTO!.workDepth,
                  isEnabled: isEnabled && !isChange,
                  onCallBack: (value) {
                    controller.executeTicketReceipt.workOtherDataDTO!.workDepth = value;
                  },
                ),
                CustomInputPage(
                  title: '作业面积',
                  text: controller.executeTicketReceipt.workOtherDataDTO!.workArea,
                  isEnabled: isEnabled && !isChange,
                  onCallBack: (value) {
                    controller.executeTicketReceipt.workOtherDataDTO!.workArea = value;
                  },
                ),
                CustomFileUploadPage(
                  isEnabled: isEnabled,
                  isChange: isChange,
                  title: '简图：',
                  isShowDivider: false,
                  uploadedFiles: controller.executeTicketReceipt.workOtherDataDTO!.simpleMapUrl,
                  onCallBack: (value) {
                    controller.executeTicketReceipt.workOtherDataDTO!.simpleMapUrl = value;
                  },
                ),
                CustomMultiSignaturePage(
                  title: '签字',
                  isEnabled: isEnabled,
                  isChange: isChange,
                  signatureLists: controller.executeTicketReceipt.workOtherDataDTO!.sign,
                  onCallBack: (value) {
                    controller.executeTicketReceipt.workOtherDataDTO!.sign = value;
                  },
                ),
                CustomSelectPage(
                    title: '时间',
                    isEnabled: isEnabled && !isChange,
                    selectText: controller.executeTicketReceipt.workOtherDataDTO!.signTime!,
                    onCallBack: () {
                      CustomSelectFunction.selectDateTime(onCallBack: (String value) {
                        controller.executeTicketReceipt.workOtherDataDTO!.signTime = value;
                        controller.update();
                      });
                    }),
                CustomFileUploadPage(
                  isRequired: false,
                  isShowDivider: false,
                  isEnabled: isEnabled,
                  isChange:isChange,
                  uploadedFiles: controller.executeTicketReceipt.workPlan,
                  title: '作业方案：',
                  onCallBack: (value) {
                    controller.executeTicketReceipt.workPlan = value;
                  },
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }

  ///获取作业负责人信息
  Widget _getUnitLeaderView() {
    return CustomSelectWorkUserPage(
        title: '作业负责人',
        isEnabled: isEnabled && !isChange,
        operatorType: 1,
        isShowCertificateNumber: false,
        queryParameters: const {
          'roleName': '作业负责人',
        },
        dataList: controller.executeTicketReceipt.operatorLists,
        onCallBack: (value) {
          controller.executeTicketReceipt.operatorLists = value;
        });
  }

  ///获取监护人信息
  Widget _getGuardianView() {
    return CustomSelectWorkUserPage(
        title: '监护人',
        isEnabled: isEnabled && !isChange,
        operatorType: 2,
        isShowCertificateNumber: false,
        queryParameters: const {
          'roleName': '监护人',
        },
        dataList: controller.executeTicketReceipt.operatorLists,
        onCallBack: (value) {
          controller.executeTicketReceipt.operatorLists = value;
        });
  }

  ///获取剩余信息
  Widget _getRemainingView() {
    return Container(
      padding: EdgeInsets.symmetric(horizontal: 13.w),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(8.w),
      ),
      child: Column(
        children: [
          CustomSelectRelationPage(
            isEnabled: isEnabled && !isChange,
            selectedWork: controller.executeTicketReceipt.otherTicketNo,
            onCallBack: (value) {
              controller.executeTicketReceipt.otherTicketNo = value;
            },
            isShowDivider: false,
          ),
        ],
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.symmetric(horizontal: 14.w, vertical: 12.w),
      margin: EdgeInsets.only(bottom: 60.w),
      color: const Color(0xFFF5F5F6),
      alignment: Alignment.topCenter,
      child: GetBuilder(
          init: controller,
          builder: (_) {
            if (controller.executeTicketReceipt.id!.isEmpty) {
              return Container();
            }
            return SingleChildScrollView(
                child: Column(
              children: [
                // 作业基本信息
                _getBasicJobWidget(),
                AppGaps.vGap20,
                // 负责人
                _getUnitLeaderView(),
                AppGaps.vGap20,
                // 监护人
                _getGuardianView(),
                AppGaps.vGap20,
                // 剩余信息
                _getRemainingView(),
              ],
            ));
          }),
    );
  }
}
